<html>
	<head>
    
		<title>Trombino - Evaluation étudiant</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<script type="text/javascript" src="public/js/jquery.min.js"></script>
		<script type="text/javascript" src="public/js/d3.v2.js"></script>
		<script type="text/javascript">
		//tableau des raisons
		var arrRaisons = {0:"abscent", 1:"présent", 2:"retard", 3:"travail non fait"};

		//enregistrement de la raison d'un clic
		function saveRaison(raison, etu) {
			//récupère les informations de l'étudiant
			var nom = $("#etu_nom_"+etu).text();
			var r = arrRaisons[raison];
			var url = $("#etu_tof_"+etu).attr("src");
			var p = {"raison":r, "etu":nom, "url":url};
			
			$.get("ecrire.php", p,
					 function(data){
						dataCloud = data;
					 }, "json");}
			
			/*$.post("public/evaletu/ecrire", p,
					 function(data){
						dataCloud = data;
					 }, "json");
		}*/
		
		//récupération des raison d'un étudiant
		function getRaison(etu) {
			//récupère les informations de l'étudiant
			var nom = $("#etu_nom_"+etu).text();
			var p = {"etu":nom};
			$.get("lire.php", p,
					 function(data){
						dessineGraph(data, etu);
					 }, "json");
		}

		//dessine le graphe svg
		function dessineGraph(data, etu){
			var svg = d3.select("#etu_svg_"+etu).append("svg")
		    .attr("width", 100)
		    .attr("height", 100);
		    /*
			.append("rect")
				.attr("x", 10)
				.attr("fill", "green")
			    .attr("width", 200)
			    .attr("y", 10)
			    .attr("height", 20);
		    */
			svg.selectAll(".bar")
		      .data(data)
		    .enter().append("rect")
		      .attr("class", "bar")
		      .attr("x", function(d, i) { 
			      return 10*i; 
			      })
		      .attr("width", 10)
		      .attr("y", function(d) { 
			      return 0; 
			      })
		      .attr("height", function(d, i) { 
			      return 10*i; 
			      });		    
		}
		</script>
		
		<style>
		.btn {
			cursor:pointer; 
		}
		.tof {
			width:200px; 
		}
		.good {
			color:green;
		}
		.bad {
			color:red;
		}
		.bar {
		  fill: steelblue;
		}
		body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  margin: auto;
  position: relative;
  width: 800px;
}

text {
  font: 10px sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

form {
  right: 10px;
  top: 10px;
}
		</style>
		
	</head>
	<body >	
    <center>
    <meta charset="utf-8">
    
    
    <?php 
    $xml = simplexml_load_file("https://picasaweb.google.com/data/feed/base/user/113848708930851956597/albumid/5795380358275112865?alt=rss&kind=photo&hl=fr");
	
	$i=0;
	foreach ($xml->channel->item as $item){
		echo "<div id='etu_".$i."' >";
		
		if($i % 2 == 0) $c = 'good'; else $c = 'bad'; 
		echo "Etudiant n° $i :";echo "$c <br>";
		echo "<div class='$c' id='etu_nom_".$i."'>".$item->title."</div>";
		echo "<img id='etu_tof_".$i."' src='".$item->enclosure['url']."' class='tof'onclick='getRaison(".$i.")' /> <br>";
		echo "<img src='public/img/timeP.jpg' class='btn' onclick='saveRaison(1,".$i.")' />";
		echo "<img src='public/img/timeR.jpg' class='btn' onclick='saveRaison(2,".$i.")' />";
		echo "<img src='public/img/timeA.jpg' class='btn' onclick='saveRaison(0,".$i.")' /> <br><br>";
		
		
		
		echo "<div id='etu_svg_".$i."'></div>";
		echo "</div>";
		$i++;
	}
	?>

<form>
  <label>Resultats: <br><input type="radio" name="mode" value="grouped">Séparés</label>
  <label><input type="radio" name="mode" value="stacked" checked>Regroupés</label>
</form>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>

var n = 3, // number of layers
    m = 19, // number of samples per layer
    stack = d3.layout.stack(),
    layers = stack(d3.range(n).map(function() { return bumpLayer(m, .1); })),
    yGroupMax = d3.max(layers, function(layer) { return d3.max(layer, function(d) { return d.y; }); }),
    yStackMax = d3.max(layers, function(layer) { return d3.max(layer, function(d) { return d.y0 + d.y; }); });

var margin = {top: 40, right: 10, bottom: 20, left: 10},
    width = 800 - margin.left - margin.right,
    height = 350 - margin.top - margin.bottom;

var x = d3.scale.ordinal()
    .domain(d3.range(m))
    .rangeRoundBands([0, width], .08);

var y = d3.scale.linear()
    .domain([0, yStackMax])
    .range([height, 0]);

var color = d3.scale.linear()
    .domain([0, n - 1])
    .range(["#F62D37", "#6CD568"]);

var xAxis = d3.svg.axis()
    .scale(x)
    .tickSize(0)
    .tickPadding(6)
    .orient("bottom");

var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

var layer = svg.selectAll(".layer")
    .data(layers)
  .enter().append("g")
    .attr("class", "layer")
    .style("fill", function(d, i) { return color(i); });

var rect = layer.selectAll("rect")
    .data(function(d) { return d; })
  .enter().append("rect")
    .attr("x", function(d) { return x(d.x); })
    .attr("y", height)
    .attr("width", x.rangeBand())
    .attr("height", 0);

rect.transition()
    .delay(function(d, i) { return i * 10; })
    .attr("y", function(d) { return y(d.y0 + d.y); })
    .attr("height", function(d) { return y(d.y0) - y(d.y0 + d.y); });

svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis);

d3.selectAll("input").on("change", function change() {
  if (this.value === "grouped") transitionGrouped();
  else transitionStacked();
});

function transitionGrouped() {
  y.domain([0, yGroupMax]);

  rect.transition()
      .duration(500)
      .delay(function(d, i) { return i * 10; })
      .attr("x", function(d, i, j) { return x(d.x) + x.rangeBand() / n * j; })
      .attr("width", x.rangeBand() / n)
    .transition()
      .attr("y", function(d) { return y(d.y); })
      .attr("height", function(d) { return height - y(d.y); });
}

function transitionStacked() {
  y.domain([0, yStackMax]);

  rect.transition()
      .duration(500)
      .delay(function(d, i) { return i * 10; })
      .attr("y", function(d) { return y(d.y0 + d.y); })
      .attr("height", function(d) { return y(d.y0) - y(d.y0 + d.y); })
    .transition()
      .attr("x", function(d) { return x(d.x); })
      .attr("width", x.rangeBand());
}

// Inspired by Lee Byron's test data generator.
function bumpLayer(n, o) {

  function bump(a) {
    var x = 10,//1 / (.1 + Math.random()),
        y = 10,//2 * Math.random() - .5,
        z = 10;//10 / (.1 + Math.random());
    for (var i = 0; i < n; i++) {
      var w = 10;//(i / n - y) * z;
      a[i] += 10;//x * Math.exp(-w * w);
    }
  }

  var a = [], i;
  for (i = 0; i < n; ++i) a[i] =10;// o + o * Math.random();
  for (i = 0; i < 5; ++i) bump(a);
  return a.map(function(d, i) { return {x: i, y: Math.max(0, d)}; })

}

</script>
    
	
    </center>
   


	</body>
</html>
